package remote
{
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	
	import mx.controls.Alert;
	import mx.rpc.AbstractOperation;
	import mx.rpc.AsyncToken;
	import mx.rpc.remoting.mxml.RemoteObject;
	
	public class RemoteObjectInvoker extends EventDispatcher implements IInvoker
	{
		private var ro:RemoteObject;
		private var _defaultFaultListener:Function;
		public function RemoteObjectInvoker(dest:String,defaultFaultListener:Function=null)
		{
			ro = new RemoteObject(dest);
			Alert.show(dest);
		}
		
		public function invoke(method:String, args:Array):IInvokeResponder
		{
			var oper:AbstractOperation = ro.getOperation(method);
			Alert.show(method);
			var token:AsyncToken = oper.send.apply(oper,args);
			return new AsyncResponder(token,_defaultFaultListener);
		}
	}
}